package com.wc.AlgoOJ_train.train1.c4.A413;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/10 15:42
 * 中间距离两边最近
 * @description 简易版之最短距离
 * http://43.138.190.70:8888/p/A413
 */
public class Main {
    static FastReader sc = new FastReader();

    public static void main(String[] args) {
        int m = sc.nextInt();
        while (m-- > 0) {
            int n = sc.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = sc.nextInt();
            }
            Arrays.sort(arr);
            int mid = n / 2;
            long ans = 0;
            for (int i = 0; i < n; i++) {
                ans += Math.abs(arr[i] - arr[mid]);
            }
            System.out.println(ans);
        }
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }
}
